<script type="text/javascript" src="/js/jquery.fancybox.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery.fancybox.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/css/jquery.fancybox-thumbs.css" />
<script type="text/javascript" src="/js/jquery.fancybox-thumbs.js"></script>  
<script type="text/javascript">
 var isIE = 0;
 if (+[1,]){//非IE
 	isIE = 0;	
 }else {//IE
 	isIE = 1;
 	
 }
 var ship_method = "";			//<{$lang.product}>的<{$lang.shipping_method}>
$(function(){
	$('.fancybox-thumbs').fancybox({
		prevEffect	: 'none',
		nextEffect	: 'none',
		helpers	: {
			title	: {
				type: 'outside'
			},
			overlay	: {
				opacity : 0.8,
				css : {
					'background-color' : '#000'
				}
			},
			thumbs	: {
				width	: 50,
				height	: 50
			}
		}
	});	
	
	$("#errorTip").dialog({
			autoOpen : false,
			width : 400,
			modal : true,
			show : "slide",
			buttons:{
			"<{$lang.close}>":function(){				
				$(this).dialog("close");			
			}
		}
	});	
	
	$("#scanTip").dialog({
			autoOpen : false,
			width : 400,
			modal : true,
			show : "slide",
			buttons:{
			"<{$lang.ok}>":function(){				
				printNewPickup();
				location.reload();
				$(this).dialog("close");			
			}
		}
	});
	
	$("#messageTip").dialog({
			autoOpen : false,
			width : 400,
			modal : true,
			show : "slide",
			buttons:{
			"<{$lang.close}>":function(){
				location.reload();
				$(this).dialog("close");			
			}
		}
	});
	
})

function printNewPickup(){
	window.open ('/warehouse/onepiece/print-new-pickup');		
}

function pickupConfirm(){
	var op_code = $('[name=op_code]').val();
	
	var tip = '';
	loading();
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/warehouse/onepiece/pickup-info", //请求的处理url
		data:{'op_code':op_code },
		success: function(json) {				
			if(json.ask){	
				$("#pickup_code").html(json.op_code);
				$("#sacned").html(json.sacned);
				$("#noscan").html(json.noscan);
				if(json.last_pack_orders_code!=''){
					link = "/warehouse/one-piece/print-pop/orders_code/"+json.last_pack_orders_code+"/ordersCode/"+json.last_pack_orders_code+"/reprint/1";
    		    	$("#print_result").append("<div><a href='"+link+"' target='_blank'><{$lang.last}><{$lang.associate}><{$lang.orders_code}>："+json.last_pack_orders_code+"<{$lang.print}></a></div>");
	    		}			
			}else{
				$.each(json.msg,function(key,val){
					tip += val+'<br />';	
				});					
				$("#errorTip").html(tip).dialog("open");
			}
		}
	});
	closeLoading();
	$('#product_sku').focus();
}

function productConfirm(){
	var op_code = $('[name=op_code]').val();
	var productStr = $('[name=productStr]').val();
	
	var tip = '';
	loading();
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/warehouse/onepiece/product-info", //请求的处理url
		data:{'op_code':op_code,'productStr':productStr},
		success: function(json) {				
			if(json.ask == 1){
				var html = '';
				var sacned = parseInt($("#sacned").text());
				var noscan = parseInt($("#noscan").text());
				$("#sacned").html(sacned+1);
				$("#noscan").html(noscan-1);					// ----<{$lang.update}><{$lang.quantity}>----
				var product = json.product;
				
				html += '<tr id="'+product.product_id+'">';
				html += '<td>'+product.customer_id+'-'+product.product_sku+'</td>';
				html += '<td>'+product.product_title+'</td>';
				html += '<td>'+product.product_title_cn+'</td>';
				html += '<td>';
					html += "<img src='/product/product/view-picture/id/"+product.product_id+"' height='75'>";
				html += '</td>';
				
				html += '<td class="quantity"> 1 </td>';	// 一票一件 <{$lang.quantity}>都为 1 
            	html += '<td> 1 </td>';
            	html += '</tr>';
            	
            	$('#order_products').html(html);
				$('#pp_name').text(json.pp_name);
				$("#tracking_number").val(json.tracking_number);	//设置<{$lang.shipping}><{$lang.code}>
				$("#orders_code").val(json.orders_code);
				$("#shipping_method").val(product.shipping_method);		//设置<{$lang.shipping_method}><{$lang.code}> 测试用
				ship_method = product.shipping_method;			//<{$lang.product}>的<{$lang.shipping_method}>
				
				printFp();		
			}else{
				$.each(json.msg,function(key,val){
					tip += val+'<br />';	
				});					
				$("#errorTip").html(tip).dialog("open");
			}
		}
	});
	closeLoading();
	
	var noscan = parseInt($("#noscan").text());
	if(noscan == 0){		
		var tip = op_code + ' <{$lang.product}><{$lang.all}><{$lang.scan}><{$lang.finish}>。';
		$("#messageTip").html(tip).dialog("open");
	}
	
	$("#productStr").select();
	
}

function printFp()
{		
	if(isIE&&ship_method!="EPACKET"){
		alertTip("<{$lang.pls_use}>firefox");
		return false;
	}
	loading();
	var tn=$("#orders_code").val();		//<{$lang.shipping}><{$lang.code}>
	if(tn==''){
		alertTip('<{$lang.order}><{$lang.code}><{$lang.can_not_be_empty}>');
		return;
	}
	$.ajax({
        type: "POST",
        async: false,
        dataType: "html",
        url: "/warehouse/onepiece/print-pop/orders_code/"+tn+"/ordersCode/"+$("#orders_code").val()+"/",
        success: function(json) {     	

        	var html = "";        	
    		html = json;
    		var link = "";
    		
    		var  pwin=window.open("a.html","print",'height=200, width=200, top=-200, left=-200, toolbar=no, menubar=no, scrollbars=yes,resizable=yes');   
         	pwin.document.write(html);   
          	pwin.document.close();             //这句很重要哦  
         	
         	if(isIE){
	         	pwin.document.all.WebBrowser.ExecWB(6,2);
         	}else{
         		pwin.print();	         		
         	}	
         	
 			closeLoading();
         	link = "/warehouse/one-piece/print-pop/orders_code/"+tn+"/ordersCode/"+$("#orders_code").val()+"/reprint/1";
    		    	
         	$("#print_result").append("<div><a href='"+link+"' target='_blank'><{$lang.orders_code}>："+$("#orders_code").val()+"<{$lang.print}></a></div>");
    			
    			
    	
			
        }
	}); 
}

function scanConfirm(){
	var op_code = $('[name=op_code]').val();
	var tip = '';
	loading();
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/warehouse/onepiece/scan-confirm", //请求的处理url
		data:{'op_code':op_code },
		success: function(json) {				
			if(json.ask){
				$.each(json.msg,function(key,val){
					tip += val+'<br />';	
				});
				if(json.op_code){
					$("#scanTip").html(tip).dialog("open");		//还有<{$lang.product}>未<{$lang.scan}>
				}else{
					$("#messageTip").html(tip).dialog("open");
				}				
			}else{
				$.each(json.msg,function(key,val){
					tip += val+'<br />';	
				});					
				$("#errorTip").html(tip).dialog("open");
			}
		}
	});
	closeLoading();
	
}

//<{$lang.operation}><{$lang.tip}>
function alertTip(tip) {
    $('<div title="<{$lang.tip}>(<{$lang.close}><{$lang.esc}>)"><p align="center">' + tip + '</p></div>').dialog({
        modal: true,        
        close:function(){    
            $("#product_sku").focus();
        }
    });
}

</script>
<style type="text/css">
.button{background:url(images/left-menu-li.gif) repeat-x left top #F1F6F9; border:1px solid #318DAC; font-weight:bold; padding:2px 5px; font-weight:lighter; color:#318DAC; vertical-align:middle; -moz-border-radius:3px; -webkit-border-radius:3px; margin:auto 5px}
#pp_name{color:red;font-weight:bold;font-size:20px;}
div.onepiece_top{
	margin-top:10px;margin-bottom:15px;
	padding:4px;	
	border:1px solid #ccc;
}
div.onepiece_top div{
	float:left;
	margin-right:5px;margin-bottom:5px;
	width:270px;height:30px;
	line-height:30px;
}
div.onepiece_top .clear{
	clear:both;
	float:none;
	height:1px;
	
}
.s_clear{clear:both;}
</style>
<iframe id="print_order" alwaysLowered=no name="print_order" src="" style="Width:100px;height:100px;left:-200px;top:-300px;position:absolute;"  ></iframe>

<div class="onepiece_top">
	<table  width="100%" cellspacing="2" cellpadding="2" border="0" style="margin-top:5px;" >
		<tr>
			<td>
			<{$lang.op_code}>： <span id="pickup_code"></span> 
			</td>
			<td>
			<{$lang.scand}>： <span id="sacned"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<{$lang.noscan}>： <span id="noscan"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 	
			<{$lang.recommend}><{$lang.package}><{$lang.name}>:<span id="pp_name"></span> 
			</td>
		</tr>
		<tr>
			<td>
			<{$lang.op_code}>： 
			<input name="op_code" class='myInput' type="text" value='' onkeyup="if(event.keyCode==13){pickupConfirm();}" /> &nbsp;
			<input type="button" value="<{$lang.ok}>" class="button" onclick="pickupConfirm()" />
			</td>
			<td>
			<{$lang.product}><{$lang.barcode}>： 
			<input name="productStr" id="productStr" class='myInput' type="text" value='' onkeyup="if(event.keyCode==13){productConfirm();}" /> &nbsp;
			<input type="button" value="<{$lang.ok}>" class="button" onclick="productConfirm()" />
			<input type="hidden" name="tracking_number" id="tracking_number" value="" />	<!-- <{$lang.shipping}><{$lang.code}> -->
			<input type="hidden" name="orders_code" id="orders_code" value="" />	<!-- <{$lang.order}><{$lang.code}> -->
			<input type="hidden" name="shipping_method" id="shipping_method" value="" />	<!--  <{$lang.shipping_method}><{$lang.code}> -->
		
			</td>
		</tr>
		<tr>
			<td colspan='2'>
			<input type="button" value="<{$lang.finish}>！" class="button" onclick="scanConfirm()" />&nbsp;
			</td>
		</tr>
	</table>
	
</div>

<table width="100%" cellspacing="0" cellpadding="0" border="0" style="margin-top:5px;"  class='myTab'>
	<tbody width="100%">
		<tr class="even-tr">			
			<th width='120'><{$lang.sku}></th>
			<th><{$lang.product}><{$lang.name}></th>
			<th><{$lang.description}></th>
			<th width='80'><{$lang.picture}></th>
			<th width='50'><{$lang.quantity}></th>
			<th width='80'><{$lang.scan}><{$lang.quantity}></th>
		</tr>
	</tbody>
	<tbody id="order_products">
		<tr class="" style="display:none;">
			<td>A0359-12345</td>
			<td><{$lang.product}><{$lang.name}></td>
			<td><{$lang.product}><{$lang.description}></td>
			<td><img src='/images/noimg.jpg' height="75"/></td>
			<td>12</td>
			<td>0</td>			
		</tr>
				
	</tbody>
</table>
<div id="print_result">

</div>
<!-- 
<script language="javascript" >
<{include file='warehouse/productsbatch/js/LodopFuncs.js'}>
</script>
<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
	<embed id="LODOP_EM" TYPE="application/x-print-lodop" width=0 height=0 PLUGINSPAGE="install_lodop.exe"></embed>
</object> 
 -->
<div id="scanTip" title="Scan tip" style="display:none">	 </div>
<div id="errorTip" title="Error tip" style="display:none">	 </div>
<div id="messageTip" title="message tip" style="display:none">	 </div>
<div id="pdfWrap" style="width:600px;height:600px;border:2px solid #ccc;display:none;left:50%;margin-left:-300px;margin-top:-300px;position:absolute;top:50%;background:#fff;">

</div>